Added additionalProperties support to shape()#198
Merged
webdeveric merged 5 commits intomasterfrom Jul 5, 2025
Merged
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR extends the shape() factory to optionally disallow extra properties and adds a helper (hasAdditionalProperties) plus tests to cover the new behavior.
- Introduce
additionalPropertiesboolean flag toshape(), defaulting totrue - Implement
hasAdditionalPropertiesutility and wire it intoshape() - Update tests and type definitions around
shape(),assume(), and add new tests forhasAdditionalProperties
Reviewed Changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/predicate/factory/shape.ts | Added additionalProperties parameter, hooked up extra-prop check |
| src/hasAdditionalProperties.ts | New utility to detect unexpected object keys |
| src/index.ts | Exported hasAdditionalProperties |
| test/predicate/factory/shape.test.ts | Updated shape tests to cover nested object and new flag |
| test/hasAdditionalProperties.test.ts | Added tests for array and object extra-property detection |
| test/predicate/factory/assume.test-d.ts | Added TypeScript signature tests for assume() |
| test/predicate/assume.test.ts | Basic runtime tests for assume() |
| bench/hasAdditionalProperties.bench.ts | Benchmark for new utility |
| src/predicate/isUnknown.ts & isAny.ts | Switched to use assume() for always-true predicates |
| src/predicate/factory/is.ts | Fixed parameter naming in is() factory |
Comments suppressed due to low confidence (3)
src/predicate/factory/shape.ts:44
- Add JSDoc for the
additionalPropertiesparameter onshape()to explain its effect and default value.
additionalProperties = true,
src/predicate/factory/shape.ts:44
- [nitpick] The parameter name
additionalPropertiescan be ambiguous; consider renaming toallowAdditionalPropertiesto more clearly indicate its boolean semantics.
additionalProperties = true,
test/predicate/factory/shape.test.ts:103
- Add a test case for the default
shape(userShape)(without passingfalse) to verify that extra properties are allowed by default, preserving backward compatibility.
it('Can check for additional properties', () => {
|
🎉 This PR is included in version 0.67.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.